package logic

import (
	"context"
	"renting-demo/cart_srv/cart"
	"renting-demo/cart_srv/internal/svc"
	"renting-demo/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type StockLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StockLogic {
	return &StockLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// todo: 脚本更新虚拟库存
func (l *StockLogic) Stock(in *cart.ProductStockReq) (*cart.Response, error) {
	mysql.Update(int(in.GoodsId), int(in.Num))

	return &cart.Response{
		Status: "1",
	}, nil
}
